﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
#if false
    /// <summary>
    /// Prefab资源引用持有者，当对象自毁时，自动清除当前引用计数
    /// </summary>
    [DisallowMultipleComponent]
    public class PrefabReferenceHolder : MonoBehaviour
    {
        [Header("Prefab引用计数脚本")]
        private PrefabReference sr;
        public int instanceId;
        private void Awake()
        {
            instanceId = gameObject.GetInstanceID();
        }

        public void Set(PrefabReference sr)
        {
            this.sr = sr;
        }

        private void OnDestroy()
        {
            //自动销毁时，清除对象池中的引用
            GameObjectPool.Instance.Free(this.instanceId);
        }
    }

#else
    [DisallowMultipleComponent]
    public class PrefabReferenceHolder : MonoBehaviour
    {
        public int instanceId;
        private void Awake()
        {
            instanceId = gameObject.GetInstanceID();
        }


        private void OnDestroy()
        {
          
            GameObjectPool.Instance.Free(this.instanceId);
        }

    }
#endif
}
